package com.huike.web.controller.business;

import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.vo.BusinessTrackVo;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.enums.BusinessType;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/business")
public class TbBusinessTrackRecordController extends BaseController {

    @Autowired(required = false)
    private ITbBusinessTrackRecordService tbBusinessTrackRecordService;

    @PreAuthorize("@ss.hasPermi('business:record:add')")
    @Log(title = "商机跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessTrackVo businessTrackVo) {
        System.out.println("-------"+businessTrackVo);
        TbBusinessTrackRecord trackRecord = new TbBusinessTrackRecord();
        BeanUtils.copyProperties(businessTrackVo, trackRecord);
        trackRecord.setCreateTime(DateUtils.getNowDate());
        trackRecord.setCreateBy(SecurityUtils.getUsername());

        TbBusiness business = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo, business);
        business.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        business.setId(businessTrackVo.getBusinessId());

        return toAjax(tbBusinessTrackRecordService.insertTbBusinessTrackRecord(business,trackRecord));
    }
}